import dayjs from 'dayjs'
import 'dayjs/locale/zh-cn'
import zhCN from 'antd/locale/zh_CN'
import { ConfigProvider, App } from 'antd'
import { lazy, Suspense } from 'react'
import { createBrowserRouter, RouterProvider } from 'react-router-dom'

import { judgeBrowserVersion } from '../Utils'
import { IndexedDBFun } from '../Utils/IndexedDB'
import { useFavicon } from 'ahooks'
import { ImageUrl } from '../Config/theme'

dayjs.locale('zh-cn')
const LogIn = lazy(() => import('../Login'))
const Loading = lazy(() => import('../View/Loading/LoadSvg'))
const VersionTips = lazy(() => import('../View/Other/VersionTips'))
const Admin = lazy(() => import('../Admin'))
const Start = lazy(() => import(`../Start`))
const Page = lazy(() => import(`../Start/Page`))
const Home = lazy(() => import(`../Start/Home`))

const RouterMapping = [
    { path: '/', element: <LogIn /> },
    { path: 'Admin', element: <Admin /> },
    {
        path: 'Start',
        element: <Start />,
        children: [
            { path: 'Home/:uuid?', element: <Home /> },
            { path: 'Page/:page/:uuid?', element: <Page /> },
        ]
    }
]
const router = createBrowserRouter(RouterMapping, { future: { v7_normalizeFormMethod: true } })


const RouterIndex = () => {
    window.webDB = IndexedDBFun()


    useFavicon(ImageUrl + 'icon.ico')

    return (
        <ConfigProvider locale={zhCN}>
            <App>
                <Suspense fallback={<Loading />} >
                    {judgeBrowserVersion() ? <RouterProvider router={router} /> : <VersionTips />}
                </Suspense>
            </App>
        </ConfigProvider>
    )
}

export default RouterIndex;